using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQSZNTVOR
    {
        public DataRow Convert2QSZNTVOR(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQSZNTVOR(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["QSTMANDANT"] = " ".PadRight(2 ); 
         dwReturn["QSTAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["QSTAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["QSTAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["QSTSZENNR"] = " ".PadRight(8 ); 
         dwReturn["QSTLSG"] = " ".PadRight(0 ); 
         dwReturn["QSTSTARTPUNKT"] = " ".PadRight(0 ); 
         dwReturn["QSTBRTVON"] = " ".PadRight(0 ); 
         dwReturn["QSTBRTBIS"] = " ".PadRight(0 ); 
         dwReturn["QSTAENZL"] = " ".PadRight(0 ); 
         dwReturn["QSTAENB"] = " ".PadRight(8 ); 
         dwReturn["QSTAEND"] = " ".PadRight(0 ); 
         dwReturn["QSTNEUB"] = " ".PadRight(8 ); 
         dwReturn["QSTNEUD"] = " ".PadRight(0 ); 
         dwReturn["QSTSTKID"] = " ".PadRight(0 ); 
         dwReturn["QSTAPOS"] = " ".PadRight(4 ); 
         dwReturn["QSTZENSUR"] = " ".PadRight(2 ); 
         dwReturn["QSTGKREGEL"] = " ".PadRight(8 ); 
         dwReturn["QSTGUETEKL"] = " ".PadRight(8 ); 
         dwReturn["QSTENDPUNKT"] = " ".PadRight(0 ); 
         dwReturn["QSTABSCHNITT"] = " ".PadRight(2 ); 
         dwReturn["QSTANZABSSTK"] = " ".PadRight(2 ); 
         dwReturn["QSTSTKLAENGE"] = " ".PadRight(0 ); 
         dwReturn["QSTKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["QSTPROBE"] = " ".PadRight(1 ); 
         dwReturn["QSTKUNDENPROBE"] = " ".PadRight(1 ); 
         dwReturn["QSTGRATISPROBE"] = " ".PadRight(1 ); 
         dwReturn["QSTANZSHD"] = " ".PadRight(2 ); 
         dwReturn["QSTANZPKTFEHL"] = " ".PadRight(0 ); 
         dwReturn["QSTANZLNGFEHL"] = " ".PadRight(0 ); 
         dwReturn["QSTANZNAEHTE"] = " ".PadRight(0 ); 
         dwReturn["QSTANZFEHLPKT"] = " ".PadRight(0 ); 
         dwReturn["QSTPFVERGUET"] = " ".PadRight(0 ); 
         dwReturn["QSTLFVERGUET"] = " ".PadRight(0 ); 
         dwReturn["QSTVERGUETUNG"] = " ".PadRight(0 ); 
         dwReturn["QSTREPKOST"] = " ".PadRight(0 ); 
         dwReturn["QSTURKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["QSTURSTKNR"] = " ".PadRight(12 ); 
         dwReturn["QSTFILLER"] = " ".PadRight(44 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQSZNTVOR(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQSZNTVOR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQSZNTVOR(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQSZNTVOR(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQSZNTVOR(dwLocal, ITXDBVERSION);
            }
            UpdateQSZNTVOR(dwLocal);
        }
        public void InsertQSZNTVOR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QSZNTVOR(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQSZNTVOR(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QSZNTVOR WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QSZNTVOR  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QSZNTVOR";
            Return = Result;
            return Return;
        }
        public void DeleteQSZNTVOR(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QSZNTVOR   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQSZNTVOR(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QSZNTVOR SET "
                    +"QSTMANDANT= :QSTMANDANT,"
                    +"QSTAUFKRS= :QSTAUFKRS,"
                    +"QSTAUFLFD= :QSTAUFLFD,"
                    +"QSTAUFPOS= :QSTAUFPOS,"
                    +"QSTSZENNR= :QSTSZENNR,"
                    +"QSTLSG= :QSTLSG,"
                    +"QSTSTARTPUNKT= :QSTSTARTPUNKT,"
                    +"QSTBRTVON= :QSTBRTVON,"
                    +"QSTBRTBIS= :QSTBRTBIS,"
                    +"QSTAENZL= :QSTAENZL,"
                    +"QSTAENB= :QSTAENB,"
                    +"QSTAEND= :QSTAEND,"
                    +"QSTNEUB= :QSTNEUB,"
                    +"QSTNEUD= :QSTNEUD,"
                    +"QSTSTKID= :QSTSTKID,"
                    +"QSTAPOS= :QSTAPOS,"
                    +"QSTZENSUR= :QSTZENSUR,"
                    +"QSTGKREGEL= :QSTGKREGEL,"
                    +"QSTGUETEKL= :QSTGUETEKL,"
                    +"QSTENDPUNKT= :QSTENDPUNKT,"
                    +"QSTABSCHNITT= :QSTABSCHNITT,"
                    +"QSTANZABSSTK= :QSTANZABSSTK,"
                    +"QSTSTKLAENGE= :QSTSTKLAENGE,"
                    +"QSTKUNDNR= :QSTKUNDNR,"
                    +"QSTPROBE= :QSTPROBE,"
                    +"QSTKUNDENPROBE= :QSTKUNDENPROBE,"
                    +"QSTGRATISPROBE= :QSTGRATISPROBE,"
                    +"QSTANZSHD= :QSTANZSHD,"
                    +"QSTANZPKTFEHL= :QSTANZPKTFEHL,"
                    +"QSTANZLNGFEHL= :QSTANZLNGFEHL,"
                    +"QSTANZNAEHTE= :QSTANZNAEHTE,"
                    +"QSTANZFEHLPKT= :QSTANZFEHLPKT,"
                    +"QSTPFVERGUET= :QSTPFVERGUET,"
                    +"QSTLFVERGUET= :QSTLFVERGUET,"
                    +"QSTVERGUETUNG= :QSTVERGUETUNG,"
                    +"QSTREPKOST= :QSTREPKOST,"
                    +"QSTURKUNDNR= :QSTURKUNDNR,"
                    +"QSTURSTKNR= :QSTURSTKNR,"
                    +"QSTFILLER= :QSTFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("QSTMANDANT", OracleType.NVarChar).Value = dwData["QSTMANDANT"].ToString(); 
          or1.Parameters.Add("QSTAUFKRS", OracleType.NVarChar).Value = dwData["QSTAUFKRS"].ToString(); 
          or1.Parameters.Add("QSTAUFLFD", OracleType.NVarChar).Value = dwData["QSTAUFLFD"].ToString(); 
          or1.Parameters.Add("QSTAUFPOS", OracleType.NVarChar).Value = dwData["QSTAUFPOS"].ToString(); 
          or1.Parameters.Add("QSTSZENNR", OracleType.NVarChar).Value = dwData["QSTSZENNR"].ToString(); 
          or1.Parameters.Add("QSTLSG", OracleType.NVarChar).Value = dwData["QSTLSG"].ToString(); 
          or1.Parameters.Add("QSTSTARTPUNKT", OracleType.NVarChar).Value = dwData["QSTSTARTPUNKT"].ToString(); 
          or1.Parameters.Add("QSTBRTVON", OracleType.NVarChar).Value = dwData["QSTBRTVON"].ToString(); 
          or1.Parameters.Add("QSTBRTBIS", OracleType.NVarChar).Value = dwData["QSTBRTBIS"].ToString(); 
          or1.Parameters.Add("QSTAENZL", OracleType.NVarChar).Value = dwData["QSTAENZL"].ToString(); 
          or1.Parameters.Add("QSTAENB", OracleType.NVarChar).Value = dwData["QSTAENB"].ToString(); 
          or1.Parameters.Add("QSTAEND", OracleType.NVarChar).Value = dwData["QSTAEND"].ToString(); 
          or1.Parameters.Add("QSTNEUB", OracleType.NVarChar).Value = dwData["QSTNEUB"].ToString(); 
          or1.Parameters.Add("QSTNEUD", OracleType.NVarChar).Value = dwData["QSTNEUD"].ToString(); 
          or1.Parameters.Add("QSTSTKID", OracleType.NVarChar).Value = dwData["QSTSTKID"].ToString(); 
          or1.Parameters.Add("QSTAPOS", OracleType.NVarChar).Value = dwData["QSTAPOS"].ToString(); 
          or1.Parameters.Add("QSTZENSUR", OracleType.NVarChar).Value = dwData["QSTZENSUR"].ToString(); 
          or1.Parameters.Add("QSTGKREGEL", OracleType.NVarChar).Value = dwData["QSTGKREGEL"].ToString(); 
          or1.Parameters.Add("QSTGUETEKL", OracleType.NVarChar).Value = dwData["QSTGUETEKL"].ToString(); 
          or1.Parameters.Add("QSTENDPUNKT", OracleType.NVarChar).Value = dwData["QSTENDPUNKT"].ToString(); 
          or1.Parameters.Add("QSTABSCHNITT", OracleType.NVarChar).Value = dwData["QSTABSCHNITT"].ToString(); 
          or1.Parameters.Add("QSTANZABSSTK", OracleType.NVarChar).Value = dwData["QSTANZABSSTK"].ToString(); 
          or1.Parameters.Add("QSTSTKLAENGE", OracleType.NVarChar).Value = dwData["QSTSTKLAENGE"].ToString(); 
          or1.Parameters.Add("QSTKUNDNR", OracleType.NVarChar).Value = dwData["QSTKUNDNR"].ToString(); 
          or1.Parameters.Add("QSTPROBE", OracleType.NVarChar).Value = dwData["QSTPROBE"].ToString(); 
          or1.Parameters.Add("QSTKUNDENPROBE", OracleType.NVarChar).Value = dwData["QSTKUNDENPROBE"].ToString(); 
          or1.Parameters.Add("QSTGRATISPROBE", OracleType.NVarChar).Value = dwData["QSTGRATISPROBE"].ToString(); 
          or1.Parameters.Add("QSTANZSHD", OracleType.NVarChar).Value = dwData["QSTANZSHD"].ToString(); 
          or1.Parameters.Add("QSTANZPKTFEHL", OracleType.NVarChar).Value = dwData["QSTANZPKTFEHL"].ToString(); 
          or1.Parameters.Add("QSTANZLNGFEHL", OracleType.NVarChar).Value = dwData["QSTANZLNGFEHL"].ToString(); 
          or1.Parameters.Add("QSTANZNAEHTE", OracleType.NVarChar).Value = dwData["QSTANZNAEHTE"].ToString(); 
          or1.Parameters.Add("QSTANZFEHLPKT", OracleType.NVarChar).Value = dwData["QSTANZFEHLPKT"].ToString(); 
          or1.Parameters.Add("QSTPFVERGUET", OracleType.NVarChar).Value = dwData["QSTPFVERGUET"].ToString(); 
          or1.Parameters.Add("QSTLFVERGUET", OracleType.NVarChar).Value = dwData["QSTLFVERGUET"].ToString(); 
          or1.Parameters.Add("QSTVERGUETUNG", OracleType.NVarChar).Value = dwData["QSTVERGUETUNG"].ToString(); 
          or1.Parameters.Add("QSTREPKOST", OracleType.NVarChar).Value = dwData["QSTREPKOST"].ToString(); 
          or1.Parameters.Add("QSTURKUNDNR", OracleType.NVarChar).Value = dwData["QSTURKUNDNR"].ToString(); 
          or1.Parameters.Add("QSTURSTKNR", OracleType.NVarChar).Value = dwData["QSTURSTKNR"].ToString(); 
          or1.Parameters.Add("QSTFILLER", OracleType.NVarChar).Value = dwData["QSTFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
